home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / linux-image-3.2.0-4-486.prerm < prev    next >
Encoding:
Text File  |  2012-12-19  |  4.1 KB  |  164 lines

  1. #! /usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Debconf::Client::ConfModule qw(:all);
  5. version('2.0');
  6. my $capb=capb("backup");
  7.  
  8. $|=1;
  9. # Predefined values:
  10. my $version         = "3.2.0-4-486";
  11. my $kimage          = "vmlinuz";
  12. my $prerm_hook      = '';       #Normally we do not
  13. my $kernel_arch       = "x86";
  14. my $package_name    = "linux-image-$version";
  15.  
  16. #known variables
  17. my $realimageloc    = "/boot/";
  18. my $CONF_LOC        = '/etc/kernel-img.conf';
  19.  
  20. # Variables used
  21. my $image='';
  22. my $ret=0;
  23. my $seen='';
  24. my $answer='';
  25. my $running = '';
  26. my $WouldInvalidate = 0;
  27.  
  28. # Ignore all invocations uxcept when called on to remove
  29. exit 0 unless ($ARGV[0] && $ARGV[0] =~ /remove/) ;
  30.  
  31. if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
  32.   if (open(CONF, "$CONF_LOC")) {
  33.     while (<CONF>) {
  34.       chomp;
  35.       s/\#.*$//g;
  36.       next if /^\s*$/;
  37.  
  38.       $prerm_hook      = "$1"  if /prerm_hook\s*=\s*(\S+)/i;
  39.     }
  40.     close CONF;
  41.   }
  42. }
  43.  
  44.  
  45. $ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
  46.  
  47. #check to see if we are trying to remove a running kernel
  48. # if so we abort right now.
  49. chop($running=`uname -r`);
  50. if ($running eq $version) {
  51.   my $question = "${package_name}/prerm/removing-running-kernel-$version";
  52.  
  53.   ($ret,$seen) = fset ("$question", 'seen', 'false');
  54.   die "Error setting debconf flags in $question: $seen" if $ret;
  55.  
  56.   $ret = subst("$question", 'running', "$running");
  57.   die "Error setting debconf substitutions in $question: $seen" if $ret;
  58.  
  59.   ($ret,$seen) = input('critical', "$question");
  60.   if ($ret && $ret != 30 ) {
  61.     die "Error setting debconf question $question: $seen";
  62.   }
  63.  
  64.   ($ret,$seen) = go ();
  65.   if ($ret && $ret != 30 ) {
  66.     die "Error asking debconf question $question: $seen";
  67.   }
  68.  
  69.   ($ret,$answer) = get("$question");
  70.   die "Error retreiving answer for $question: $answer" if $ret;
  71.  
  72.   if ($answer =~ /^(y|t)/i) {
  73.     print STDERR "Aborting removal of running kernel image.\n";
  74.     exit 1; #Operation not permitted
  75.   }
  76.   else {
  77.      print STDERR "Ok, proceeding with removing running kernel image.\n";
  78.   }
  79. }
  80.  
  81. #Now, they have an alternate kernel which they are currently running
  82.  
  83. chdir("/") or die "could not chdir to /:$!\n";
  84.  
  85.  
  86. # set the env var stem
  87. $ENV{'STEM'} = "linux";
  88.  
  89. sub exec_script {
  90.   my $type   = shift;
  91.   my $script = shift;
  92.   print STDERR "Running $type hook script $script.\n";
  93.   system ("$script $version $realimageloc$kimage-$version") &&
  94.     print STDERR "User $type hook script [$script] ";
  95.   if ($?) {
  96.     if ($? == -1) {
  97.       print STDERR "failed to execute: $!\n";
  98.     }
  99.     elsif ($? & 127) {
  100.       printf STDERR "died with signal %d, %s coredump\n",
  101.         ($? & 127),  ($? & 128) ? 'with' : 'without';
  102.     }
  103.     else {
  104.       printf STDERR "exited with value %d\n", $? >> 8;
  105.     }
  106.     exit $? >> 8;
  107.   }
  108. }
  109. sub run_hook {
  110.   my $type   = shift;
  111.   my $script = shift;
  112.   if ($script =~ m,^/,) {
  113.     # Full path provided for the hook script
  114.     if (-x "$script") {
  115.       &exec_script($type,$script);
  116.     }
  117.     else {
  118.       die "The provided $type hook script [$script] could not be run.\n";
  119.     }
  120.   }
  121.   else {
  122.     # Look for it in a safe path
  123.     for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
  124.       if (-x "$path/$script") {
  125.         &exec_script($type, "$path/$script");
  126.         return 0;
  127.       }
  128.     }
  129.     # No luck
  130.     print STDERR "Could not find $type hook script [$script].\n";
  131.     die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
  132.   }
  133. }
  134.  
  135.  
  136. my $options;
  137. for (@ARGV) {
  138.     s,','\\'',g;
  139.     $options .= " '$_'";
  140. }
  141. $ENV{'DEB_MAINT_PARAMS'}="$options";
  142.  
  143. ## Run user hook script here, if any
  144. if (-x "$prerm_hook") {
  145.   &run_hook("prerm", $prerm_hook);
  146. }
  147. if (-d "/etc/kernel/prerm.d") {
  148.   print STDERR "Examining /etc/kernel/prerm.d.\n";
  149.   system ("run-parts --verbose --exit-on-error --arg=$version " . 
  150.           "--arg=$realimageloc$kimage-$version /etc/kernel/prerm.d") &&
  151.             die "Failed to process /etc/kernel/prerm.d";
  152. }
  153. if (-d "/etc/kernel/prerm.d/$version") {
  154.   print STDERR "Examining /etc/kernel/prerm.d/$version.\n";
  155.   system ("run-parts --verbose --exit-on-error --arg=$version" .
  156.           " --arg=$realimageloc$kimage-$version " .
  157.           "/etc/kernel/prerm.d/$version") &&
  158.             die "Failed to process /etc/kernel/prerm.d/$version";
  159. }
  160.  
  161. exit 0;
  162. __END__
  163.